//
//  addFriendVC.m
//  HappyStore
//
//  Created by 陈锋 on 16/6/23.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "addFriendVC.h"
#import "friendModel.h"
#import "addressCell.h"

#import <MessageUI/MessageUI.h>
@interface addFriendVC ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate,UISearchDisplayDelegate,UIActionSheetDelegate,MFMessageComposeViewControllerDelegate>{

    UISearchDisplayController *searchDisplayController;
    UISearchBar *searchBar;
    NSArray *searchResults;
    NSString * tel;
    NSString * userName;
    NSMutableArray * nameArr;
    
    NSArray * yiZhuCeArr;
    NSArray * yiTianJiaArr;
    
    NSMutableArray * headArr;
}
@property (weak, nonatomic) IBOutlet UITableView *tableview;
@property (nonatomic, strong) NSMutableArray *addressBookArray; // 存放所有的联系人信息
@property(nonatomic,strong)NSMutableArray *indexArray;//索引
@property(nonatomic,strong)NSMutableArray *letterResultArr;//title
@property (strong, nonatomic)NSMutableDictionary * modelDict;
@end

@implementation addFriendVC

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    
    self.tabBarController.tabBar.hidden = YES;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置导航栏title的字体大小等
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:19],NSFontAttributeName,[UIColor whiteColor],NSForegroundColorAttributeName, nil]];
    self.title = @"我的人脉";
    
    headArr = [NSMutableArray array];
    
    //设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"Back" highImage:@"Back"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.sectionIndexBackgroundColor = [UIColor clearColor];
    self.tableview.sectionIndexTrackingBackgroundColor=[UIColor clearColor];
    self.tableview.sectionIndexColor = [UIColor grayColor];
    self.addressBookArray = [[NSMutableArray alloc] init];
    [self getAddressBookArray];// 得到手机通信录信息
    
    nameArr = [NSMutableArray array];
    _modelDict = [NSMutableDictionary dictionary];
    
    for (friendModel * model in self.addressBookArray) {
        
        if (!model.name) {
            model.name = model.tel;
        }
        
        if (model.tel) {
            
            [_modelDict setValue:model forKey:model.name];
            [nameArr addObject:model.name];
        }
        
        
    }
    
    //匹配数据
    [self sendRequest];
    
    self.indexArray = [[NSMutableArray alloc]initWithObjects:@"推荐", nil];
    NSMutableArray * indexs = [ChineseString IndexArray:nameArr];
    [self.indexArray addObjectsFromArray:indexs];
    self.letterResultArr = [ChineseString LetterSortArray:nameArr];
    
    [self.tableview reloadData];
    
    //搜索框
    searchBar = [[UISearchBar alloc] init];
    searchBar.delegate = self;
    searchBar.placeholder = @"搜索";
    [searchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone];
    
    [searchBar sizeToFit];
    searchBar.x = 6;
    UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenW, 44)];
    headView.backgroundColor = [UIColor colorWithRed:201.0/255.0 green:201.0/255.0 blue:206.0/255.0 alpha:1];
    [headView addSubview:searchBar];
    
    self.tableview.tableHeaderView = headView;

    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    
    [searchDisplayController setDelegate:self];
    
    [searchDisplayController setSearchResultsDataSource:self];
    
    [searchDisplayController setSearchResultsDelegate:self];
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope {
    
    NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@",                                     searchText];
    
    searchResults = [NSArray array];
    
    searchResults = [nameArr filteredArrayUsingPredicate:resultPredicate];

    NSLog(@"%@",searchResults);
    
}




#pragma mark - UISearchDisplayController delegate methods

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller  shouldReloadTableForSearchString:(NSString *)searchString {
    
    [self filterContentForSearchText:searchString  scope:[[self.searchDisplayController.searchBar scopeButtonTitles]  objectAtIndex:[self.searchDisplayController.searchBar                                                      selectedScopeButtonIndex]]];

    
    return YES;
    
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller  shouldReloadTableForSearchScope:(NSInteger)searchOption {
    
    [self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
    
    return YES;
    
}
-(void)leftBarButtonItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.tabBar.hidden = NO;
}
#pragma mark - 获取系统通讯录
- (void)getAddressBookArray
{
    //新建一个通讯录类
    ABAddressBookRef addressBooks = nil;
    
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0)// 判断当前设备的系统版本,因为iOS6之后获取通讯录的方式有变化
        
    {
        addressBooks =  ABAddressBookCreateWithOptions(NULL, NULL);
        
        //获取通讯录权限
        dispatch_semaphore_t sema = dispatch_semaphore_create(0); // 参考http://blog.csdn.net/robincui2011/article/details/9270249
        
        ABAddressBookRequestAccessWithCompletion(addressBooks, ^(bool granted, CFErrorRef error){dispatch_semaphore_signal(sema);}); // 请求访问的用户地址簿数据
        
        dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); // 等待一个信号量
        
    }
    else
    {
        addressBooks = ABAddressBookCreateWithOptions(NULL, NULL);
        
    }
    
    //获取通讯录中的所有人
    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBooks);
    
    //通讯录中人数
    CFIndex nPeople = ABAddressBookGetPersonCount(addressBooks);
    
    //循环，获取每个人的个人信息
    for (NSInteger i = 0; i < nPeople; i++)
    {
        //新建一个addressBook model类
        friendModel *addressBook = [[friendModel alloc] init];
        //获取个人
        ABRecordRef person = CFArrayGetValueAtIndex(allPeople, i);
        //获取个人名字
        CFTypeRef abName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
        CFTypeRef abLastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
        CFStringRef abFullName = ABRecordCopyCompositeName(person);
        NSString *nameString = (__bridge NSString *)abName;
        NSString *lastNameString = (__bridge NSString *)abLastName;
        
        if ((__bridge id)abFullName != nil) {
            nameString = (__bridge NSString *)abFullName;
        } else {
            if ((__bridge id)abLastName != nil)
            {
                nameString = [NSString stringWithFormat:@"%@ %@", nameString, lastNameString];
            }
        }
        addressBook.name = nameString;
        addressBook.recordID = (int)ABRecordGetRecordID(person);
        //获取头像
        NSData *imageData = (__bridge NSData*)ABPersonCopyImageData(person);
        UIImage *image = [UIImage imageWithData:imageData];
        addressBook.img = image;
        
        ABPropertyID multiProperties[] = {
            kABPersonPhoneProperty,
            kABPersonEmailProperty
        };
        NSInteger multiPropertiesTotal = sizeof(multiProperties) / sizeof(ABPropertyID);
        for (NSInteger j = 0; j < multiPropertiesTotal; j++) {
            ABPropertyID property = multiProperties[j];
            ABMultiValueRef valuesRef = ABRecordCopyValue(person, property);
            NSInteger valuesCount = 0;
            if (valuesRef != nil) valuesCount = ABMultiValueGetCount(valuesRef);
            
            if (valuesCount == 0) {
                CFRelease(valuesRef);
                continue;
            }
            //获取电话号码和email
            for (NSInteger k = 0; k < valuesCount; k++) {
                CFTypeRef value = ABMultiValueCopyValueAtIndex(valuesRef, k);
                switch (j) {
                    case 0: {// Phone number
                        addressBook.tel = (__bridge NSString*)value;
                        NSString * str10 = [addressBook.tel stringByReplacingOccurrencesOfString:@" " withString:@""];
                        NSString * str11 = [str10 stringByReplacingOccurrencesOfString:@"-" withString:@""];
                        NSString * str12 = [str11 stringByReplacingOccurrencesOfString:@"+86" withString:@""];
                        addressBook.tel = str12;
                        
                        break;
                    }
                    case 1: {// Email
                        addressBook.email = (__bridge NSString*)value;
                        break;
                    }
                }
                CFRelease(value);
            }
            CFRelease(valuesRef);
        }
        //将个人信息添加到数组中，循环完成后addressBookTemp中包含所有联系人的信息
        [self.addressBookArray addObject:addressBook];
        if (abName) CFRelease(abName);
        if (abLastName) CFRelease(abLastName);
        if (abFullName) CFRelease(abFullName);
        
    }
}

#pragma mark - UITableViewDataSource

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    if (tableView == searchDisplayController.searchResultsTableView){
        return nil;
    }else{
    return self.indexArray;
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView == searchDisplayController.searchResultsTableView){
        return 1;
    }else{
    return [self.indexArray count];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == searchDisplayController.searchResultsTableView){
        return searchResults.count;
        
    }else{
        
        if (section == 0) {
            
            if (headArr.count > 0) {
                
                return headArr.count;
                
            }else{
            
                return 1;
            
            }
            
        }else{
        
    return [[self.letterResultArr objectAtIndex:section - 1] count];
            
        }
        
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    // 注册
    UINib * nib = [UINib nibWithNibName:@"addressCell" bundle:nil];
    
    [self.tableview registerNib:nib forCellReuseIdentifier:CellIdentifier];
    addressCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    [searchDisplayController.searchResultsTableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[addressCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
    NSString * name;
    
    cell.addBtn.layer.masksToBounds = YES;
    cell.addBtn.layer.borderColor = [UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f].CGColor;
    cell.addBtn.layer.borderWidth = 1.5f;
    cell.addBtn.layer.cornerRadius = 5.0f;
    [cell.addBtn setTitleColor:[UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f] forState:0];
    [cell.addBtn setBackgroundColor:[UIColor whiteColor]];
    [cell.addBtn setTitle:@"邀请" forState:0];
    
    if (tableView == searchDisplayController.searchResultsTableView){
        
        name = searchResults[indexPath.row];
        
    }else{
        
        if (indexPath.section == 0) {
            
            if (headArr.count > 0 && allConstMemberid) {
                
                NSDictionary * dict = headArr[indexPath.row];
                cell.name.text = dict[@"userName"];
                cell.phone.text = dict[@"phone"];
                NSString * str = [NSString stringWithFormat:@"%@",dict[@"userId"]];
                cell.addBtn.tag = [str integerValue];
                [cell.addBtn setTitleColor:[UIColor whiteColor] forState:0];
                [cell.addBtn setBackgroundColor:[UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f]];
                
                if ([dict[@"typeWithUser"] isEqualToString:@"zhuce"]) {
                    
                    [cell.addBtn setTitle:@"添加" forState:0];
                    
                }else if ([dict[@"typeWithUser"] isEqualToString:@"tianjia"]){
                
                    [cell.addBtn setTitle:@"会话" forState:0];
                
                }
                
                
            }else{
            
                cell.name.text = @"暂无推荐";
            
            }
            
        }else{
        
        name = [[self.letterResultArr objectAtIndex:indexPath.section - 1]objectAtIndex:indexPath.row];
            
            friendModel * model = [_modelDict valueForKey:name];
            cell.name.text = model.name;
            cell.phone.text = model.tel;
            
            if (allConstMemberid) {
                
                for (NSDictionary * dict in yiZhuCeArr) {
                    
                    if ([dict[@"phone"] isEqualToString:model.tel]) {
                        
                        NSString * str = [NSString stringWithFormat:@"%@",dict[@"userId"]];
                        
                        [cell.addBtn setTitleColor:[UIColor whiteColor] forState:0];
                        [cell.addBtn setBackgroundColor:[UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f]];
                        
                        cell.addBtn.tag = [str integerValue];
                        [cell.addBtn setTitle:@"添加" forState:0];
                        
                    }
//                    else {
//                        
//                        [cell.addBtn setTitleColor:[UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f]  forState:0];
//                        [cell.addBtn setBackgroundColor:[UIColor whiteColor]];
//                        
//                    }
                    
                }
                
                        for (NSDictionary * dict in yiTianJiaArr) {
                            
                            if ([dict[@"phone"] isEqualToString:model.tel]) {
                                
                                NSString * str = [NSString stringWithFormat:@"%@",dict[@"userId"]];
                                
                                [cell.addBtn setTitleColor:[UIColor whiteColor] forState:0];
                                [cell.addBtn setBackgroundColor:[UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f]];
                                
                                cell.addBtn.tag = [str integerValue];
                                [cell.addBtn setTitle:@"会话" forState:0];
                                
                            }
//                            else{
//                                
//                                [cell.addBtn setTitleColor:[UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f]  forState:0];
//                                [cell.addBtn setBackgroundColor:[UIColor whiteColor]];
//                                
//                            }
                        }
            
                    }
            
                }
    
    cell.imageview.image = [UIImage imageNamed:@"touxiang"];
    cell.imageview.layer.masksToBounds = YES;
    cell.imageview.layer.cornerRadius = 5.0f;
    
}
    
    
    [cell.addBtn addTarget:self action:@selector(clickPeople:) forControlEvents:UIControlEventTouchUpInside];
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    if (tableView == searchDisplayController.searchResultsTableView){
        return 0;
    }else{
    return index;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 65.0;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if (tableView == searchDisplayController.searchResultsTableView){
        return nil;
    }else{
        
        if (section == 0) {
            
            return  @"推荐";
            
        }else{
        
    NSString *key = [self.indexArray objectAtIndex:section];
    return key;
            
        }
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];//取消选中状态
    NSString * name;
    if (tableView == searchDisplayController.searchResultsTableView){
        
        name = searchResults[indexPath.row];
        
    }else{
        
        if (indexPath.section == 0) {
            
            NSDictionary * dict = headArr[indexPath.row];
            name = dict[@"userName"];
            tel = dict[@"phone"];
            
        }else{
        
        name = [[self.letterResultArr objectAtIndex:indexPath.section - 1]objectAtIndex:indexPath.row];
            friendModel * model = [_modelDict valueForKey:name];
            tel = model.tel;
            userName = model.name;
            
        }
    }
    
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:name
                                                             delegate:self
                                                    cancelButtonTitle:@"取消"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:tel,@"发送邀请消息", nil];


    [actionSheet showInView:self.view];
    
     // 给对应号码发短信
//     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"sms://%@",[NSNumber numberWithInteger:[tel integerValue]]]]];
    

}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
    
        case 0:
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",tel]]];
        }
            break;
        case 1:
        {
            
            NSString * body = [NSString stringWithFormat:@"乐商网】是一个高效便捷的商务信息共享平台,快来获取更多的优质商务信息吧!下载地址：https://itunes.apple.com/us/app/le-shang-wang/id1070850954?l=zh&ls=1&mt=8 记得安装后加我好友哦：%@",userName];
            [self showMessageView:[NSArray arrayWithObjects:tel, nil] title:@"邀请信息" body:body];

        }
            break;
            
        case 2:
            // 取消
            break;
            
        default:
            break;
    }
    
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body
{
    if( [MFMessageComposeViewController canSendText] )
    {
        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
        controller.recipients = phones;
        controller.navigationBar.tintColor = [UIColor redColor];
        controller.body = body;
        controller.messageComposeDelegate = self;
        [self presentViewController:controller animated:YES completion:nil];
        [[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面标题
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"
                                                        message:@"该设备不支持短信功能"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil, nil];
        [alert show];
    }
}

-(void)clickPeople:(UIButton *)button{
    
    if (allConstMemberid) {
        
        if ([button.titleLabel.text isEqualToString:@"邀请"]) {
            
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"请点击名称发送邀请消息" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles: nil];
            
            [alert show];
            
        }else if([button.titleLabel.text isEqualToString:@"添加"]){
            
            [self showRoundProgressWithTitle:@"加载中..."];
            
            NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
 
                [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户

                [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];//验证用户
            
                [muDicParameters setObject:@(button.tag) forKey:@"targetuserId"];


            NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"isAddFriend_app_social.im.lensum"];
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
                
            } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                
                NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                //                    NSString * jsonStr = [LSHttpTool DataTOjsonString:dicInfo];
                //                                NSLog(@"--------------------json:%@",jsonStr);
                

                
                if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                    
                    [self showRightWithTitle:[dicInfo objectForKey:@"msg"] autoCloseTime:2];

                    
                }else {

                    [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                }
                

            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                [self showSingleIconBubble:error.localizedDescription];
                
            }];

            
        
        
        }else if([button.titleLabel.text isEqualToString:@"会话"]){
            NSDictionary * dictSession = [NSDictionary dictionary];
            
            for (NSDictionary * dict in yiTianJiaArr) {
                
                if ([dict[@"userId"] integerValue] == button.tag) {
                    
                    dictSession = dict;
                    
                }
                
                
            }
            
            IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
            manager.enable = NO;
            manager.shouldResignOnTouchOutside = NO;
            manager.shouldToolbarUsesTextFieldTintColor = NO;
            manager.enableAutoToolbar = NO;
            
            sessionVC *chatVc = [[sessionVC alloc] init];
            chatVc.title = dictSession[@"userName"];
            chatVc.conversationType = ConversationType_PRIVATE;
            chatVc.targetId = dictSession[@"account"];
            chatVc.enableUnreadMessageIcon = YES;
            chatVc.enableNewComingMessageIcon = YES;
            chatVc.defaultHistoryMessageCountOfChatRoom = 50;
            
            [self.navigationController pushViewController:chatVc animated:YES];

        
        }
        
    }else{
    
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"登录后系统自动匹配更多信息" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登录", nil];
        [alert show];
    
    }


}

#pragma mark - alertview
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
    }
    
    
}
#pragma mark - 匹配数据
-(void)sendRequest{
    [self showRoundProgressWithTitle:@"加载中..."];
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    
    if (allConstMemberid) {
        
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
        
    }else{

        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
    }

    
    
    NSMutableString * phoneStr = [[NSMutableString alloc] init];
    
    for (friendModel * model in self.addressBookArray) {
        
        NSString * str2 = [NSString stringWithFormat:@"%@,",model.tel];
        [ phoneStr appendString:str2];
    }
    
    [muDicParameters setObject:phoneStr forKey:@"phone"];//电话
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"getUserPhone_app_social.im.lensum"];

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//                    NSString * jsonStr = [LSHttpTool DataTOjsonString:dicInfo];
//                                NSLog(@"--------------------json:%@",jsonStr);


        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            
            yiZhuCeArr = dicInfo[@"data"][@"yizhuce"];
            yiTianJiaArr = dicInfo[@"data"][@"yitianjia"];
            

            
            for (int i = 0 ; i < yiZhuCeArr.count; i++) {
                
                NSMutableDictionary * dict = [[NSMutableDictionary alloc]initWithDictionary:yiZhuCeArr[i]];
                [dict setObject:@"zhuce" forKey:@"typeWithUser"];
                [headArr addObject:dict];
                
            }
            
            for (int i = 0 ; i < yiTianJiaArr.count; i++) {
                
                NSMutableDictionary * dict = [[NSMutableDictionary alloc]initWithDictionary:yiTianJiaArr[i]];
                [dict setObject:@"tianjia" forKey:@"typeWithUser"];
                [headArr addObject:dict];
                
            }
            
            [self hideBubble];
            [self.tableview reloadData];

        }else {

           [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];

        }
        

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        [self showSingleIconBubble:error.localizedDescription];

    }];
}
@end
